package com.ruoyi.rsikManage.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.rsikManage.domain.Config;
import com.ruoyi.rsikManage.domain.vo.BroadcastSwitch;
import com.ruoyi.rsikManage.service.BroadcastService;
import com.ruoyi.rsikManage.service.ConfigService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletContext;
import java.util.List;

@RestController
@RequestMapping("/rsikManage/config")
public class ConfigController extends BaseController {
    @Autowired
    private ConfigService configService;
    @Autowired
    ServletContext servletContext;
    /**
     * 查询配置列表
     */
//    @GetMapping("list")
//    public TableDataInfo getConfigList (){
//        startPage();
//        List<Config> list = configService.getConfigList();
//        return getDataTable(list);
//    }
    /**
     * 查询广播播放开关列表（用于前端展示）
     */
    @GetMapping("broadcastSwitch")
    public TableDataInfo selectBroadcastSwitchList (){
        startPage();
        List<BroadcastSwitch> list = configService.selectBroadcastSwitchList();
        return getDataTable(list);
    }

    /**
     * 修改广播播放开关
     */
    @GetMapping("updateBroadcastSwitch")
    public AjaxResult updateBroadcastPlaySwitch(@RequestParam Integer switchStatus) {
        switchStatus = switchStatus > 0 ? 1 : 0;
        configService.updateBroadcastPlaySwitch(switchStatus);
        servletContext.setAttribute("broadcastPlaySwitch", switchStatus);
        return success();
    }
}
